package com.mapmymotion;

import java.util.HashMap;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleAdapter;

public class ActivitiesAdapter extends SimpleAdapter {
	  Resources res;
//private int[] colors = new int[] { 0x30FFFFFF, 0x3066FF66,0x30FFFF00 };
	  private int[] colors = new int[] {  0x3066FF66,0x30FFFF00 };	  
JSONObject json_data;

 
public ActivitiesAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
    super(context, items, resource, from, to);

}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
  View view = super.getView(position, convertView, parent);

  res = mainActivity.getContext().getResources();
  int colorPos = position % colors.length;
  // Load the image and set it on the ImageView
  ImageView imageView = (ImageView) view.findViewById(R.id.activitytype);
  //imageView.setImageDrawable(res.getDrawable(R.drawable.runner));
	try {
		//json_data = JWC.jArray.getJSONObject(position);
		json_data = JWC.getActivities().getJSONObject(position);
		String s_activitytype=json_data.getString("activitytype");
		
		if(s_activitytype.contentEquals("RUN")){
			imageView.setImageDrawable(res.getDrawable(R.drawable.runner));}
		if(s_activitytype.contentEquals("CYC")){
			imageView.setImageDrawable(res.getDrawable(R.drawable.bicycle));}
		if(s_activitytype.contentEquals("WHC")){
			imageView.setImageDrawable(res.getDrawable(R.drawable.wheelchair));}
		if(s_activitytype.contentEquals("WLK")){
			imageView.setImageDrawable(res.getDrawable(R.drawable.walker));}
		if(s_activitytype.contentEquals("SKI")){
			imageView.setImageDrawable(res.getDrawable(R.drawable.skiing));}
		if(s_activitytype.contentEquals("SWM")){
			imageView.setImageDrawable(res.getDrawable(R.drawable.swimming));}
		if(s_activitytype.contentEquals("OTH")){
			imageView.setImageDrawable(res.getDrawable(R.drawable.circle));}
	} catch (JSONException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	
  view.setBackgroundColor(colors[colorPos]);

  

  return view;
}
}